public class Solution6 {
    //找出链表中 开始入环的第一个结点;如果没环返回null
    public ListNode detectCycle(ListNode head) {
            ListNode fast = head;
            ListNode slow = head;
            while(fast != null && fast.next != null) {
                fast = fast.next.next;
                slow = slow.next;
                if(fast == slow) {
                    break;
                }
            }
            if(fast == null || fast.next == null) {
                return null;
            }
            ListNode cur = head;
            while(cur != slow) {
                cur = cur.next;
                slow = slow.next;
            }
            return cur;
    }
}
